
<div id="{{$pageID}}">
    <h2>网站模板套系</h2>
    <table id="site_theme_setting" class="table table-striped">
    <?php
        $tableHeaders =  $this->Html->tableHeaders(array(
            '模板目录名称',
            '最后修改时间',
			'PC模板套系',
			'手机模板套系'
        ),array('class'=>'info'));

        echo '<thead>'.$tableHeaders.'</thead>';

        $rows = array();
        foreach ($sitetpls AS $tpl) {
            //$actions = ' ' . $this->Html->link(__('Edit', true), array('controller'=>'stylevars','action' => 'edit', $tpl['name']));
            //$actions .= ' ' . $this->Html->link(__('Delete', true), array('action' => 'delete', $style['Misccate']['id']), null, __('Are you sure?', true));
			if($site_theme==$tpl['name']){
				$active = '<button data-theme="'.$tpl['name'].'" data-mode="theme" type="button" class="theme-btn btn btn-small btn-default disabled"><i class="icon-ok icon-white"></i>已启用</button>';
			}
			else{
				$active = '<button data-theme="'.$tpl['name'].'" data-mode="theme" type="button" class="theme-btn btn btn-small btn-primary">启用此套系</button>';
			}
			if($mobile_theme==$tpl['name']){
				$mobile_active = '<button data-theme="'.$tpl['name'].'" data-mode="mobile_theme" type="button" class="mobile_theme-btn btn btn-small btn-default disabled"><i class="icon-ok icon-white"></i>已启用</button>';
			}
			else{
				$mobile_active = '<button data-theme="'.$tpl['name'].'" data-mode="mobile_theme" type="button" class="mobile_theme-btn btn btn-small btn-primary">启用此套系</button>';
			}
            $rows[] = array(
                $tpl['name'],
                $tpl['time'],
				$active,$mobile_active,
            );
        }
        echo $this->Html->tableCells($rows);
    ?>
    </table>
    <div> <small><input type="text" id="site-folder-name"> <button onclick="createfolder('site',$('#site-folder-name').val());" class="btn btn-primary btn-small">新建网站模板目录</button></small></div>
    <hr/>
    <h2>后台系统模板套系 </h2>
    <table id="admin_theme_setting" class="table table-striped">
    <?php
        $tableHeaders =  $this->Html->tableHeaders(array(
            '模板目录名称',
            '最后修改时间',
			'是否启用',
        ),array('class'=>'info'));

        echo '<thead>'.$tableHeaders.'</thead>';

        $rows = array();
        foreach ($tpls AS $tpl) {
            //$actions = ' ' . $this->Html->link(__('Edit', true), array('controller'=>'stylevars','action' => 'edit', $tpl['name']));
            //$actions .= ' ' . $this->Html->link(__('Delete', true), array('action' => 'delete', $style['Misccate']['id']), null, __('Are you sure?', true));
			if($admin_theme==$tpl['name']){
				$active = '<button data-theme="'.$tpl['name'].'" type="button" class="btn btn-small btn-default disabled"><i class="icon-ok icon-white"></i>已启用</button>';
			}
			else{
				$active = '<button data-theme="'.$tpl['name'].'" type="button" class="btn btn-small btn-primary">启用此套系</button>';
			}
			$rows[] = array(
                $tpl['name'],
                $tpl['time'],
				$active,
            );
        }
        echo $this->Html->tableCells($rows);
    ?>
    </table>
    <div>
    	<small><input type="text" id="admin-folder-name"> <button onclick="createfolder('admin',$('#admin-folder-name').val());" class="btn btn-primary btn-small">新建后台模板目录</button></small>
    </div>
    
</div>
<script>

function createfolder(type,name){
	if(name==''){
		alert('请输入名称');return false;
	}
	ajaxAction(ADMIN_BASEURL+'/admin/tools/createThemeFolder',{type:type,name:name});
}

$(function(){
	/* 网站模板 */
	$('#site_theme_setting').find('button').unbind('click').click(function(){
		var obj = this;
		if($(this).hasClass('disabled')){
			return false;
		}
		var post_data = {};
		var mode = $(this).data('mode');
		post_data['setting[Site]['+ mode +']'] = $(this).data('theme');
		$.ajax({
			async:true,
			type:'post',
			success:function(request, xhr) {				
				//showDialogMessage(request);
				$('#site_theme_setting').find('.'+mode+'-btn').removeClass('disabled').addClass('btn-primary').html('启用此套系');
				$(obj).removeClass('btn-primary').addClass('disabled').html('<i class="icon-ok icon-white"></i>已启用');
			},
			url:ADMIN_BASEURL+'/admin/settings/ajaxesave',
			data:post_data,
			dataType:'json'
		}) ;
		return false;
	});
	/* 后台模板 */
	$('#admin_theme_setting').find('button').unbind('click').click(function(){
		var obj = this;
		if($(this).hasClass('disabled')){
			return false;
		}
		$.ajax({
			async:true,
			type:'post',
			success:function(request, xhr) {				
				//showDialogMessage(request);
				$('#admin_theme_setting').find('.btn-success').removeClass('btn-success').removeClass('disabled').addClass('btn-primary').html('启用此套系');
				$(obj).removeClass('btn-primary').addClass('disabled').html('<i class="icon-ok icon-white"></i>已启用');
			},
			url:ADMIN_BASEURL+'/admin/settings/ajaxesave',
			data:{'setting[Admin][theme]':$(this).data('theme')},
			dataType:'json'
		}) ;
		return false;
	})
})

</script>